# coding=utf-8
from Unit.Request import request
from Unit.Search import search
from Unit.Search import match


def Format(string):
    string = str(string)
    string1 = string.replace(':', '：')
    string2 = string1.replace('.', '^^')
    string3 = string2.replace('"', '“')
    string4 = string3.replace('(', '（')
    string5 = string4.replace(')', '）')
    string6 = string5.replace("'", '’')
    return string6


def crack(key, lock):
    lock = Format(lock)
    # 请求字符数据
    response = request(key)
    items = []
    if response is not None:
        item = search(lock, response)
        for it in item:
            key = list(it.keys())[0]
            value = list(it.values())[0]
            if len(value) == 1:
                items.append(key)
            else:
                # 进入数据库匹配
                items.append(match(it))
    value = str(''.join(items)).replace('^^','.')
    return value


if __name__ == '__main__':
    pass
